package cn.pigeon.usermanager.intercepter;

import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

public class LoginIntercepter implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        String requestURI = request.getRequestURI();
        System.out.println(requestURI);
        HttpSession session = request.getSession();
        if(session.getAttribute("user")!=null){
            //已登陆，放行
            return true;
        }else{
            //未登陆，跳转到登陆页面
            response.sendRedirect(request.getContextPath()+"/login.jsp");
            return false;
        }
    }
}
